package com.zhiketuan.webserver.model;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/**
 * 所有操作结果返回模型
 *
 * @author 凡梦星尘(elkan1788@gmail.com)
 */
@ApiModel(value = "返回结果模型", description = "返回结果模型")
public class ResponseResult implements Serializable {

    private static final int SUCCESS_CODE = 200;
    private static final int ERROR_CODE = 500;

    private static final String SUCCESS_MSG = "OK";

    @ApiModelProperty(value = "操作代码", required = true)
    private Integer code;
    @ApiModelProperty(value = "操作描述", required = true)
    private String message;
    @ApiModelProperty(value = "操作数据", required = true)
    private Object data;

    public static ResponseResult ok(Object data) {
       return new ResponseResult(SUCCESS_CODE, SUCCESS_MSG, data);
    }

    public static ResponseResult error(String errorMsg) {
       return new ResponseResult(ERROR_CODE, errorMsg, null);
    }

    public static ResponseResult error(String errorMsg, Object data) {
       return new ResponseResult(ERROR_CODE, errorMsg, data);
    }

    public ResponseResult() {
    }

    public ResponseResult(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResponseResult{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
